#include<iostream>
#include<cstdio>
#include<map>
#include<string>
#define N 1005
using namespace std;
int n;
string s;
map<string,int> ma;
bool getnum(string s,int &p,int &a,int num){
	if(s[p]<'0'||s[p]>'9') return false;
	if(s[p]=='0'){
		p++;
		if(s[p+1]>='0'&&s[p+1]<='9') return false;
		a=0;
		return true;
	}
	while(s[p]>='0'&&s[p]<='9'){
		a=a*10+s[p]-'0';
		p++;
	}
	if(a<=num) return true;
	return false;
}
bool check(string s){
	s+="!";
	int a=0,b=0,c=0,d=0,e=0,p=0;
	if(!getnum(s,p,a,255)) return false;
	if(s[p]!='.') return false;
	p++;
	if(!getnum(s,p,b,255)) return false;
	if(s[p]!='.') return false;
	p++;
	if(!getnum(s,p,c,255)) return false;
	if(s[p]!='.') return false;
	p++;
	if(!getnum(s,p,d,255)) return false;
	if(s[p]!=':') return false;
	p++;
	if(!getnum(s,p,e,65535)) return false;
	if(s[p]!='!') return false;
	return true;
}
int main(){
	freopen("network.in","r",stdin);
	freopen("network.out","w",stdout);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>s;
		if(s[0]=='S'){
			cin>>s;
			if(check(s)){
				if(ma[s]){
					cout<<"FAIL\n";
				}else{
					ma[s]=i;
					cout<<"OK\n";
				}
			}else{
				cout<<"ERR\n";
			}
		}else{
			cin>>s;
			if(check(s)){
				if(ma[s]){
					cout<<ma[s]<<'\n';
				}else{
					cout<<"FAIL\n";
				}
			}else{
				cout<<"ERR\n";
			}
		}
	}
}
